package cn.yuanqiao.web.controller.archive.formManage;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.storeRoom.service.InitializationService;

import cn.yuanqiao.common.domain.YqField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import cn.yuanqiao.archive.formManage.detail.domain.YqformManageDetail;
import cn.yuanqiao.archive.formManage.detail.service.IYqformManageDetailService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;

/**
 * 表单明细Controller
 * 
 * @author lyk
 * @date 2023-06-25
 */
@RestController
@RequestMapping("/archive/formManageDetail")
public class YqformManageDetailController extends BaseController
{
    @Autowired
    private IYqformManageDetailService yqformManageDetailService;

    @Autowired
    private InitializationService initializationService;

    /**
     * 查询表单明细列表
     */
    @PreAuthorize("@ss.hasPermi('archive:formManageDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(YqformManageDetail yqformManageDetail,String pageNum,String pageSize)
    {
        /*startPage();
        List<YqformManageDetail> list = yqformManageDetailService.selectYqformManageDetailList(yqformManageDetail);*/
        startPage();
        List<YqField> fieldList = initializationService.getFieldList(String.valueOf(yqformManageDetail.getDetailId()));
        return getDataTable(fieldList);
    }

    /**
     * 查询表单明细列表
     */
    @PreAuthorize("@ss.hasPermi('archive:formManageDetail:list')")
    @GetMapping("/listNoPage")
    public List<YqformManageDetail> list(YqformManageDetail yqformManageDetail)
    {
        /*startPage();
        List<YqformManageDetail> list = yqformManageDetailService.selectYqformManageDetailList(yqformManageDetail);*/
        //List<YqField> fieldList = initializationService.getFieldList(String.valueOf(yqformManageDetail.getDetailId()));
        List<YqformManageDetail> list = yqformManageDetailService.selectYqformManageDetailListByManageId(yqformManageDetail);

        return list;
    }

    /**
     * 导出表单明细列表
     */
    @PreAuthorize("@ss.hasPermi('archive:formManageDetail:export')")
    @Log(title = "表单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqformManageDetail yqformManageDetail)
    {
        List<YqformManageDetail> list = yqformManageDetailService.selectYqformManageDetailList(yqformManageDetail);
        ExcelUtil<YqformManageDetail> util = new ExcelUtil<YqformManageDetail>(YqformManageDetail.class);
        util.exportExcel(response, list, "表单明细数据");
    }

    /**
     * 获取表单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:formManageDetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") String detailId)
    {
        return success(yqformManageDetailService.selectYqformManageDetailByDetailId(detailId));
    }

    /**
     * 新增表单明细
     */
    @PreAuthorize("@ss.hasPermi('archive:formManageDetail:add')")
    @Log(title = "表单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqformManageDetail yqformManageDetail)
    {
        return toAjax(yqformManageDetailService.insertYqformManageDetail(yqformManageDetail));
    }

    /**
     * 修改表单明细
     */
    @PreAuthorize("@ss.hasPermi('archive:formManageDetail:edit')")
    @Log(title = "表单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqformManageDetail yqformManageDetail)
    {
        return toAjax(yqformManageDetailService.updateYqformManageDetail(yqformManageDetail));
    }

    /**
     * 删除表单明细
     */
    @PreAuthorize("@ss.hasPermi('archive:formManageDetail:remove')")
    @Log(title = "表单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable String[] detailIds)
    {
        return toAjax(yqformManageDetailService.deleteYqformManageDetailByDetailIds(detailIds));
    }
}
